<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility"%>
<%@ include file="/public/header.jsp"%>
<%
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String truename=String.valueOf(sessionMap.get("truename"));
%>
<html>
<head>
<title>工单管理</title>
</head>
<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#gd_admin_id').combogrid({
				title:'派单人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			$("#table").datagrid({
				title:"工单管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath%>/springMVC/gd/listPageGDDel',
				rownumbers:true,
				singleSelect:true,
				fitColumns:true,
				idField:'id',
				nowrap:false,
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true},
  					{title:'项目编号',field:'xm_code',hidden:true},
				    {title:'项目名称',field:'xm_name',hidden:true},
				    {title:'客户id',field:'customer_id',hidden:true},
				    {title:'客户',field:'customer',hidden:true},
				    {title:'最新的工单内容id',field:'gd_content_id',hidden:true},
				    {title:'所属部门id',field:'dept_id',hidden:true}
				]],
				columns:[[
					{title:'工单状态',field:'gd_status',hidden:true},
				    {title:'项目编号',field:'xm_code'},
					{title:'工单进度',field:'gd_status_desc',width:80,align:'center'},
					{title:'派单人',field:'gd_admin_name',width:80,align:'center'},
					{title:'所属部门',field:'dept_name',width:100,align:'center'},
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:100,align:'center'},
					{title:'工单类型',field:'gd_type',width:10,align:'center',hidden:true},
					{title:'完工日期',field:'gd_actual_end',width:100,align:'center'},
					{title:'删除',field:'close_gd',width:60,align:'center',formatter:function(value,rowData,rowIndex){
						return"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteGD('"+rowData.id+"');\"/>&nbsp;"
					}
					}
				]],
				   rowStyler : function(index,row){
					    if(row.xm_id != ''){
							return 'background-color:#ffee00;color:red;';
					    }else{
					    	return 'background-color:#fff;color:black;';
					    }
					},
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var gd_id = row.id;
					var gd_status = row.gd_status;
					var gd_content_num = row.gd_content_num;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					 ddv.datagrid({
						title:'内容明细',
						url:'<%=contextPath%>/springMVC/gd/listGDContent?gd_id='+gd_id,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'内容id',field:'id',hidden:true},
							{title:'编号',field:'gd_content_code',hidden:true},
							{title:'',field:'desc',width:100,align:'center',formatter:function(value,row){
								
								if(row.gd_content_code == '1'){
									return "原始内容";
								}else{
									return "第"+(row.gd_content_code-1)+"次变更内容";
								}
							}},
							{title:'当前状态',field:'status',hidden:true},
							{title:'当前状态',field:'status_desc',width:100,align:'center'},
							{title:'工单内容',field:'content',width:150,align:'center'},
							{title:'工时',field:'gd_total_time',width:50,align:'center'},
							{title:'要求日期（起始）',field:'gd_start',width:100,align:'center'},
							{title:'要求日期（截止）',field:'gd_will_end',width:100,align:'center'},
							{title:'收单单位',field:'gd_worker_name',width:100,align:'center'},
							{title:'工单类型',field:'gd_type',width:100,align:'center',hidden:true}				
						]],
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function deleteGD(gd_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath%>/springMVC/gd/deleteGdInfo",
						data:"gd_id="+gd_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function doSearch2() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue2').val();
			jQuery('#gd_admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
	function doSearch() {
		var searchValue = $('#searchValue').val();
		var dept_id = $("#dept_id").combotree('getValue');
		var gd_admin_id = jQuery("#gd_admin_id").combotree('getValue');
		$('#table').datagrid('load', {
			searchValue : searchValue,
			dept_id : dept_id,
			gd_admin_id:gd_admin_id
		});
	}
</script>
<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
		</div>
		<div align="right">
			派单人：<input type="text" id="gd_admin_id" name="gd_admin_id"   style="width:100px"> &nbsp;&nbsp;
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp;
			工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="工单编号/名称" placeholder="工单编号/名称 "/>&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
</body>
</html>
